package com.da.javatest.leetCode;

/**
 * @author chenlida
 * @date 2019/1/8 17:12
 * @description
 */
public class Code129 {
    private int total = 0;

    public int sumNumbers(TreeNode root) {
        if (root == null) {
            return 0;
        }
        getTotal(root, 0);
        return total;
    }

    private void getTotal(TreeNode node, int r) {
        r = r * 10 + node.val;
        if (node.left == null && node.right == null) {
            total += r;
        }
        if (node.left != null) {
            getTotal(node.left, r);
        }
        if (node.right != null) {
            getTotal(node.right, r);
        }
    }
}
